home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / 3dlib15.zip / PROJECTW.PAS < prev    next >
Pascal/Delphi Source File  |  1992-10-27  |  6KB  |  110 lines

  1. (******************************************************************************
  2. *                                  projectW                                   *
  3. ******************************************************************************)
  4. unit projectW;
  5.  
  6. (*******************************************************************************
  7. *      this unit has 2 instances : the first one is used with the windows      *
  8. *               graphic user interface, and the other does not,                *
  9. *                                                                              *
  10. *             +-------------------------------------------------+              *
  11. *             |  this unit is NOT interfaced to the window GUI, |              *
  12. *             |   for use on a bare screen ONLY - for runTime!  |              *
  13. *             |                ****                             |              *
  14. *             +-------------------------------------------------+              *
  15. *                                                                              *
  16. *this unit handles the 3d -> 2d projections, we use 2 different methods        *
  17. *       of projections :                                                       *
  18. *                                                                              *
  19. *               A : axonometric projections, no perspective due to             *
  20. *                       distance is performed, the general way                 *
  21. *                       we can look at the coordinate system is as             *
  22. *                       follows :                                              *
  23. *                                                                              *
  24. *                               |  z axis                                      *
  25. *                               |                                              *
  26. *                              / \                                             *
  27. *                    x axis   /   \  y axis                                    *
  28. *                                                                              *
  29. *               B : perspective projections : the normal eye perspective       *
  30. *                       projection is performed, we can look at the 3d         *
  31. *                       universe we are refering to as a cube of               *
  32. *                       1000 x 1000 x 1000 integer locations, with             *
  33. *                       the x axis, and y axis parallel to the screen          *
  34. *                       x, y axis respectivly, and the z axis going into       *
  35. *                       the screen.                                            *
  36. *                                                                              *
  37. *                       we will look at the coordinate system as follows :     *
  38. *                                                                              *
  39. *                       │ Y axis                                               *
  40. *                       │                                                      *
  41. *                Z axis x------ X axis                                         *
  42. *                                                                              *
  43. *                                                                              *
  44. *******************************************************************************)
  45.  
  46. interface
  47.  
  48. uses    {graph,}
  49.         hdr3dw
  50.         ;
  51.  
  52. const
  53.         perspective     : boolean = false; 
  54.         {true = perspective, else = axonometric}
  55.  
  56. procedure calcPoint(p3d : point3d; var psc : screenPoints);
  57. procedure setPerspective;
  58. procedure resetPerspective;
  59. procedure togglePerspective;
  60.  
  61. implementation
  62.  
  63. (******************************************************************************
  64. *                                  CalcPoint                                  *
  65. ******************************************************************************)
  66. procedure CalcPoint;
  67.  {Calculate screen cordinates of 3d location into screen}
  68.  
  69. Begin with p3d, psc do begin
  70.      if Perspective then begin
  71.           z  := z + HalfWidth;
  72.           If z < 0 Then z := 0;
  73.           sX := round((x * z / HalfWidth + HalfWidth) * (MaxX / ScreenWidth));
  74.           sY := round((HalfWidth - y * z / HalfWidth) * (MaxY / ScreenWidth));
  75.      end else begin
  76.           sX := round((HalfWidth + cosine_x * x - cosine_y * y) * (MaxX / ScreenWidth));
  77.           sY := round((HalfWidth - z + sine_x * x + sine_y * y) * (MaxY / ScreenWidth));
  78.      end;
  79.      end; {with}
  80. End; { calcPoint }
  81.  
  82. (******************************************************************************
  83. *                               setPerspective                                *
  84. ******************************************************************************)
  85. procedure setPerspective;
  86. begin
  87.         perspective := true;
  88. end; {setPerspective}
  89.  
  90. (******************************************************************************
  91. *                              resetPerspective                               *
  92. ******************************************************************************)
  93. procedure resetPerspective;
  94. begin
  95.         perspective := false;
  96. end; {resetPerspective}
  97.  
  98. (******************************************************************************
  99. *                              togglePerspective                              *
  100. ******************************************************************************)
  101. procedure togglePerspective;
  102. begin
  103.         perspective := not(perspective);
  104. end; {togglePerspective}
  105.  
  106. (******************************************************************************
  107. *                                    end.                                     *
  108. ******************************************************************************)
  109. end.
  110.